package com.example.cinemaorder.consumer;
import com.example.cinemaorder.entity.vo.SearchMovieInfoVo;
import com.example.cinemaorder.entity.vo.SearchMovieVo;
import com.example.cinemaorder.service.SysMovieService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 高垚淼
 * @version 1.0
 */
@Component
public class MovieSearchConsumer {

    @Autowired
    SysMovieService sysMovieService;

    @RabbitListener(queues = "movieSearch")
    public Object dealEmail(SearchMovieInfoVo searchMovieInfoVo, Message message, Channel channel) throws IOException {
        try {
//            // 动态sql查询所有符合条件的排片信息
//            List<SearchMovieVo> search = sysMovieService.search(searchMovieInfoVo);
//            // 修改时间展示格式
//            search.stream().map(m ->
//            {
//                m.setStartTime(m.getStartTime().substring(11, 16));
//                return m;
//            })
//                    .collect(Collectors.toList());
//            return search;
            return null;
        } catch (Exception e) {
            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
            return null;
        }
    }
}
